﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminType : Form
    {
        public AdminType()
        {
            InitializeComponent();

            Thread TypeThread = new Thread(new ThreadStart(getAllType_Thread));
            TypeThread.Start();
        }

        private void getAllType_Thread()
        {
            Invoke(new MethodInvoker(getAllType));         
        }

        private void getAllType()
        {
            Table TypeVoiture = Program.Db.QueryTable("SELECT * FROM TYPE");

            this.dataType.Rows.Clear();

            foreach (Record r in TypeVoiture)
                this.dataType.Rows.Add(r.Values[0], r.Values[1]);
        }

        private void buttonAddType_Click(object sender, EventArgs e)
        {
            AddType FenAddType = new AddType();
            FenAddType.ShowDialog();
        }

        private void AdminType_Activated(object sender, EventArgs e)
        {
            Thread TypeThread = new Thread(new ThreadStart(getAllType_Thread));
            TypeThread.Start();
        }

        private void buttonDelType_Click(object sender, EventArgs e)
        {
            TYPE delType = new TYPE();
            delType.delete_Type(Convert.ToInt32(this.dataType.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllType_Thread));
            TypeThread.Start();
        }

        private void buttonUpdateType_Click(object sender, EventArgs e)
        {
            AddType FenAddType = new AddType(Convert.ToInt32(this.dataType.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddType.ShowDialog();
            // Coucou
        }

    }
}
